<template>
  <!-- 底部部分 -->
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ todoCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li @click="changeType('all')">
        <a :class="{ selected: type === 'all' }" href="#/">全部</a>
      </li>
      <li @click="changeType('active')">
        <a :class="{ selected: type === 'active' }" href="#/active">进行中</a>
      </li>
      <li @click="changeType('completed')">
        <a :class="{ selected: type === 'completed' }" href="#/completed"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" v-if="showClearBtn" @click="delAll">
      清除已完成
    </button>
  </footer>
</template>
 
<script>
export default {
  props: ['list', 'type'],

  computed: {
    todoCount() {
      return this.list.filter((item) => !item.flag).length
    },
    showClearBtn() {
      return this.list.some((item) => item.flag)
    }
  },

  methods: {
    delAll() {
      this.$emit('delAll')
    },

    changeType(type) {
      this.$emit('changeType', type)
    }
  }
}
</script>

<style scoped>
</style>